/* Name: Nguyen Le Niem
nickname:Mark Integer
sdt:01646828033
*/
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<string.h>
#include<fstream.h>
class phonghoc{
              char maphong[50];
              char* tenphong;
              int sochongoi;

      public:
      friend ostream& operator <<(ostream& niemdeptrai, phonghoc a);
      friend istream& operator >>(istream& niem, phonghoc& a);

     // istream& operator >>(istream& niem, phonghoc& a)
             phonghoc(){
                           strcpy(maphong,"");
                           tenphong=new char[50];
                           strcpy(tenphong,"");
                           sochongoi=0;
                           }
             void nhap();
             void in();

             };
            void phonghoc::nhap(){
                         cout<<"nhap ma phong:";cin>>maphong;
                         cout<<"\nnhap ten phong:";cin>>tenphong;
                         cout<<"\nso cho ngoi:";cin>>sochongoi;}
            void phonghoc::in(){
                       cout<<"("<<maphong<<","<<tenphong<<","<<sochongoi<<")";
                       cout<<endl;
                       cout<<"------------------------\n";
                       }
     ostream& operator <<(ostream& niemdeptrai, phonghoc a){
              niemdeptrai<<a.maphong<<" "<<a.tenphong<<" "<<a.sochongoi;
                       return niemdeptrai;


              }
    istream& operator >>(istream& niem, phonghoc& a){
             // cout<<"nhap ma phong:";
              niem>>a.maphong;
             // cout<<"nhap ten phong:";
              niem>>a.tenphong;
            //  cout<<"nhap so cho ngoi :";
              niem>>a.sochongoi;
              return niem;
              }
      int main(){
          phonghoc a;
          phonghoc b;
          a.nhap();
          cout<<"luu lai file:\n";
          ofstream f1("niemfile.txt");
          f1<<a;
          f1.close();
          cout<<"lay tu file:\n";
          ifstream f2("niemfile.txt");
          f2>>b;
          f2.close();
          b.in();
          getch();
          }



